<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>

<body>
<?php
/* 密码修改处理页 */
require_once("../conn/conn_db.php");   //包含数据库连接文件
if( $_POST["txt_pwd"] == ""  )
{
    echo "<script>alert('请输入原密码！');self.location='../person_pwd_update.php'</script>";
}
else if( $_POST["txt_newpwd1"] == "" )
{
    echo "<script>alert('请输入新密码！');self.location='../person_pwd_update.php'</script>";
}
else if( $_POST["txt_newpwd1"]!= $_POST["txt_newpwd2"])
{
    echo "<script>alert('两次输入的新密码不一致！');self.location='../person_center.php'</script>";
}
else
{
    $uname = $_POST["txt_name"];         //会员名称
    $password = $_POST["txt_pwd"];        //原密码
    $newpassword = $_POST["txt_newpwd1"]; //新密码
    //查询原密码是否正确
    $sql = "select * from user_info where u_name='".$uname."' and u_pwd='".$password."'"; 
    $result = $conn->query($sql);      
    if ($result->num_rows > 0)  //返回的结果行数大于0，表示原密码正确
    {
        //更新密码
        $sql = "update user_info set u_pwd='".$newpassword."' where u_name='".$uname."'"; 
        $update = $conn->query($sql); //执行SQL语句
        if($update)
        {
            echo "<script>alert('恭喜您，密码修改成功！');self.location='../person_center.php'</script>";
        }
        else
        {
            echo "<script>alert('对不起，密码修改失败！');self.location='../person_pwd_update.php'</script>";
        }
    }
    else
    {
        echo "<script>alert('对不起，原密码错误！');self.location='../person_pwd_update.php'</script>";
    }
}
?>
</body>
</html>